#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    pid_t ret=fork();
    if(ret<0)
    {
        //fail
        perror("fail");
        exit(1);
    }
    else if(ret==0)
    {
        //child
        int cnt=5;
        while(cnt--)
        {
            
            printf("i am child process: pid:%d  ppid:%d\n",getpid(),getppid()) ;
            sleep(1);
        }
    }
    else
    {
        //father
        int status=0;
        waitpid(-1,&status,0);
        if(WIFEXITED(status))
        {
            printf("singal:%d\n",status&0x7F);
            printf("coredump:%d\n",(status>>7)&0x1);
            printf("core:%d\n",WEXITSTATUS(status));
        }
    }
    return 0;
    
}
